<?php
/**
 * Message.php
 *
 * 提供表单错误信息
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://momoger.com/license
 *
 * @category	Momoger
 * @package 	Momoger_Form
 * @author 		Guya
 * @version    	1.0
 * @copyright  	Copyright © 2009 www.momoger.com All Rights Reserved.
 * @license    	http://momoger.com/license     New BSD License
 */

/**
 * Momoger_Form 表单信息提示自定义错误消息.
 *
 * @category	Momoger
 * @package 	Momoger_Form
 * @copyright  	Copyright © 2009 www.momoger.com All Rights Reserved.
 * @license    	http://momoger.com/license     New BSD License
 */
class Momoger_Form_Message {
	/**
	 * 获取自定义的消息
	 *
	 * @return array
	 */
	public static function getCustomFormExceptionMsg() {
		return array(
			'isEmpty' => 'It can not allow empty!',
			'stringEmpty' => 'It can not allow empty!',
			'notAlnum' => 'The string contains non-alphabetic or non-digit characters!',
			'regexNotMatch' => 'The string value can not be allowed!',
			'stringLengthTooShort' => 'The string length too short!',
			'stringLengthTooLong' => 'The string length too long!',
			'emailAddressInvalid' => 'The email string is not a valid email address!',
			'emailAddressInvalidHostname' => 'The email hostname part not a valid hostname!',
			'emailAddressInvalidMxRecord' => 'The email does not appear to have a valid MX record!',
			'emailAddressDotAtom' => 'The email not matched against dot-atom format!',
			'emailAddressQuotedString' => 'The email not matched against quoted-string format!',
			'emailAddressInvalidLocalPart' => 'The email is not a valid local part!',
			'emailAddressLengthExceeded' => 'The email exceeds the allowed length!'
		);
	}


	/**
	 * 获取表单验证结果失败信息
	 *
	 * @param array $errors Zend_Form 提供的错误信息
	 * @param array $labels 需要验证的 input 信息数组
	 * @return array
	 */
	public static function getExceptionMsgs(array $errors, array $labels) {
		$customExceptionMsgs = self::getCustomFormExceptionMsg();

		$errorMsgs = array();

		foreach ($labels as $input => $label) {
			if (count($errors[$input])) {
				$errorMsgs[] = $label . $customExceptionMsgs[$errors[$input][0]];
			}
		}

		return $errorMsgs;
	}
}
